<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>添加代理</title>
	<link href="../css/public.css" rel="stylesheet"/>
	<link href="../css/main.css" rel="stylesheet"/>
	<link href="../css/style.css" rel="stylesheet"/>
	<link href="../css/agent.css?v=1" rel="stylesheet"/>
	<script src="http://www.jq22.com/jquery/jquery-1.9.1.js"></script>
	<script src="../js/swiper.min.js"></script>
	<script src="../js/mobile-util.js"></script>
	<script src="../js/public.js"></script>
	<script src="../js/layer/layui.js"></script>
	<script src="../js/jquery.cookie.js"></script>

	<script>
		/*获取url参数*/
		function getUrlParam(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
			var r = window.location.search.substr(1).match(reg);  //匹配目标参数
			if (r != null) return unescape(r[2]); return null; //返回参数值
		}

		/*获取url参数end*/
	</script>

</head>
<body >

<header class="mui-bar mui-bar-nav indexheader bluebg flex">
	<div class="headerlogo" onclick="back()">
		<i class="iconfont backbtn">&#xe602;</i>
	</div>

	<div class="headertitle">
		<p>添加二级代理</p>
	</div>

	<div class="headerright timeright hide">
		<p class="timepbox iconfont">&#xe6d9;</p>
	</div>

</header>

<main class="agentbox">



	<div class="content">
		<div class="floor list7">
			<div class="myorder p">
				<div class="content30">
					<a href="javascript:void(0)">
						<div class="order">
							<div class="fl agentlistleft">
								<span>真实姓名:</span>
							</div>
							<div class="fl">
								<input type="text" value="" id="username" name="consignee" placeholder="请输入姓名">
							</div>
						</div>
					</a>
				</div>
			</div>

			<div class="myorder p">
				<div class="content30">
					<a href="javascript:void(0)">
						<div class="order">
							<div class="fl agentlistleft">
								<span>手机号码:</span>
							</div>
							<div class="fl">
								<input type="number" value="" id="mobile" name="mobile" placeholder="请输入手机号码" onkeyup="this.value=this.value.replace(/[^\d]/g,'')">
							</div>
						</div>
					</a>
				</div>
			</div>

			<div class="myorder p">
				<div class="content30">
					<a href="javascript:void(0)">
						<div class="order">
							<div class="fl agentlistleft">
								<span>性别</span>
							</div>
							<div class="sexbox" style="position: relative;display: flex;float: left">

								<div class="radiobox1">

									<input id="radio1" type="radio" name="sex" checked="checked" value="1" class="radiobox">男
									<label id="label1" for="radio1" class="seradiobox blueioactive iconfont">&#xe668;</label>


								</div>

								<div class="radiobox1" style="margin-left: .5rem;">
									<input id="radio2" type="radio"  name="sex" value="0" class="radiobox">女
									<label id="label2" for="radio2" class="seradiobox iconfont">&#xe648;</label>
								</div>
							</div>

							<input type="hidden" id="sex" value="1" placeholder="">

						</div>
					</a>
				</div>
			</div>


			<div class="myorder p">
				<div class="content30">
					<a href="javascript:void(0)">
						<div class="order">
							<div class="fl agentlistleft">
								<span>QQ号码:</span>
							</div>
							<div class="fl">
								<input type="number" value="" id="qqcode" placeholder="请输入QQ号码" name="qqcode">
							</div>
						</div>
					</a>
				</div>
			</div>

			<div class="myorder p">
				<div class="content30">
					<a href="javascript:void(0)">
						<div class="order">
							<div class="fl agentlistleft">
								<span>身份证号:</span>
							</div>
							<div class="fl">
								<input type="text" value="" id="idcard" placeholder="请输入身份证号" name="idcard">
							</div>
						</div>
					</a>
				</div>
			</div>

			<div class="myorder p">
				<div class="content30">
					<a href="javascript:void(0)">
						<div class="order">
							<div class="fl agentlistleft">
								<span>银行卡类型:</span>
							</div>
							<div class="fl">
								<input type="text" id="bandname" value="" placeholder="例如：中国工商银行" name="bandname">
							</div>
						</div>
					</a>
				</div>
			</div>


			<div class="myorder p">
				<div class="content30">
					<a href="javascript:void(0)">
						<div class="order">
							<div class="fl agentlistleft">
								<span>银行卡支行:</span>
							</div>
							<div class="fl">
								<input type="text" id="bandnameVice" value="" placeholder="例如：中国工商银行民治支行" name="bandname">
							</div>
						</div>
					</a>
				</div>
			</div>

			<div class="myorder p">
				<div class="content30">
					<a href="javascript:void(0)">
						<div class="order">
							<div class="fl agentlistleft">
								<span>银行卡号:</span>
							</div>
							<div class="fl">
								<input type="number" id="bandcard" value="" placeholder="请输入银行卡号" name="bandcard">
							</div>
						</div>
					</a>
				</div>
			</div>


			<div class="addressbtn">
				<button type="button" class="iconfont" onclick="addagent()">添加代理</button>
			</div>


		</div>
	</div>

</main>




<script>

	var tooken=$.cookie("tooken");


	if(tooken==null||tooken==undefined||tooken==""){

		window.location.href="../agent/login.html";

	}else {
		/*单选框选择*/

		$(".radiobox").change(function(){
			if($(this).is(":checked")){
				$(".blueioactive:not(:checked)").html("&#xe648;");
				$(".blueioactive:not(:checked)").removeClass("blueioactive");
				$(this).next("label").addClass("blueioactive");
				$(this).next("label").html("&#xe668;");
				$('#sex').val($(this).val());
			}
		});

		/*单选框选择end*/


		$("#mobile").keydown(function(event) {
			var reg = /^\d{11}$/;
			var value = $(this).val();
			var e = event || window.event || arguments.callee.caller.arguments[0];

			if(e.keyCode === 8) {
				return true;
			}

			if(e.keyCode == 32) {
				return false;
			}

			if(reg.test(value)) {
				return false;
			}

		});


		function addagent(){
			var name=$.cookie("tooken");

			var url="http://ht.hiberbest.com";
			//var url="http://192.168.0.132:69";

			var geturl=url+"/admin/agentapi/agent_api";

			var username=$('#username').val();
			var mobile=$('#mobile').val();
			var qqcode=$('#qqcode').val();
			var bandname=$('#bandname').val();
			var bandcard=$('#bandcard').val();
			var idcard=$('#idcard').val();
			var sex=$('#sex').val();

			var bandnameVice=$('#bandnameVice').val();

			// 判断手机号码
			if ($('#realname').val() == "") {

				alert("请输入您的真实姓名");
				$('#realname').focus();
				return false;
			}
			if(mobile == "") {
				alert("请输入手机号");

				$('#mobile').focus();
				return false;
			}else if(!checkMobile(mobile)){
				alert("手机号码格式有误");
				$('#mobile').focus();
				return false;
			}


			//验证QQ
			if(qqcode == "") {
				alert("请输入QQ号");
				$('#qqcode').focus();
				return false;
			}else if(!isQQ(qqcode)){
				alert("QQ号格式有误");
				$('#qqcode').focus();
				return false;
			}



			// 验证身份证
			if(idcard == "") {

				alert("请输入身份证号");
				$('#idcard').focus();
				return false;
			}else if(!isCardNo(idcard)){
				alert("身份证号码格式有误");
				$('#idcard').focus();
				return false;
			}



			if(username == ""){
				alert("请填写代理姓名");
				$('#username').focus();
				return false;
			}else if(bandname == ""){
				alert("请填写代理银行卡类型");
				$('#username').focus();
				return false;
			}else if(bandcard == ""){
				alert("请填写代理银行卡号");
				$('#username').focus();
				return false;
			}
			else if(bandnameVice == ""){
				alert("请填写代理银行所属支行");
				$('#bandnameVice').focus();
				return false;
			}


			$.ajax({
				type: 'post',
				url:geturl,
				dataType: "json",
				data:{
					"tooken":name,
					"agent_qq":qqcode,
					"agent_name":username,
					"mobile":mobile,
					"idcard":idcard,
					"bankcard":bandcard,
					"bankname":bandname,
					"sex":sex,
					"branch":bandnameVice
				},

				success:function(data){
					var suc=data.success;
					if(suc.code == 4013){
						alert(suc.message);
						return false;
					}else if(suc.code == 4000){
						window.location.href="levelagentindex.html?name="+name;
					}

				},error:function(){
					console.log("请检查您的网络");
				}
			})
		}

	}



</script>

</body>
</html>
